package com.hbnu.demo.controller;

import com.hbnu.demo.bean.User;
import com.hbnu.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: hjx
 * @Date: 2023/6/13 15:21
 * @Description:
 */
@RestController
public class VueHelloController {
    @Autowired
    private UserService userService;

    @GetMapping("/insert")
    public String Insert() {
        User user = new User();
        user.setId(1).setAge(20).setName("xiaohua").setAddress("江苏镇江");
        userService.updateUserById(user);
        return "数据修改成功!";
    }

    @GetMapping("/select")
    public String SelectById(@RequestParam("id") int id) {
        User user = userService.selectById(id);
        System.out.println(user);
        return "数据查找成功！";
    }
    @GetMapping("/selectAll")
    public String SelectAll(){
        List<User> userList = userService.selectAll();
        for (User user : userList) {
            System.out.println(user);
        }
        return "全部数据查找成功";
    }


}

